libxc: some xc_gnttab_* functions are not Linux specific
authorIan Campbell <ian.campbell@citrix.com>
Thu, 23 Dec 2010 15:08:21 +0000 (15:08 +0000)
committerIan Campbell <ian.campbell@citrix.com>
Thu, 23 Dec 2010 15:08:21 +0000 (15:08 +0000)
They simply make hypercalls and perform other operations via the
abstract interface. Create xc_gnttab.c and move those functions there.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Acked-by: Christoph Egger <Christoph.Egger@amd.com>
Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
tools/libxc/Makefile
tools/libxc/xc_gnttab.c [new file with mode: 0644]
tools/libxc/xc_linux.c
tools/libxc/xc_minios.c
tools/libxc/xc_netbsd.c
tools/libxc/xc_solaris.c

index 2481c6a2f5e6d5eaa2894b0c8e20170f11e49dc7..7d9307f53aca3149ce9daa93f5a6bc51b5ba6c33 100644 (file)
@@ -11,6 +11,7 @@ CTRL_SRCS-$(CONFIG_IA64) += xc_core_ia64.c
 CTRL_SRCS-y       += xc_cpupool.c
 CTRL_SRCS-y       += xc_domain.c
 CTRL_SRCS-y       += xc_evtchn.c
+CTRL_SRCS-y       += xc_gnttab.c
 CTRL_SRCS-y       += xc_misc.c
 CTRL_SRCS-y       += xc_acm.c
 CTRL_SRCS-y       += xc_flask.c
diff --git a/tools/libxc/xc_gnttab.c b/tools/libxc/xc_gnttab.c
new file mode 100644 (file)
index 0000000..e8ec12b
--- /dev/null
@@ -0,0 +1,147 @@
+/******************************************************************************
+ *
+ * Copyright (c) 2007-2008, D G Murray <Derek.Murray@cl.cam.ac.uk>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "xc_private.h"
+
+int xc_gnttab_op(xc_interface *xch, int cmd, void * op, int op_size, int count)
+{
+    int ret = 0;
+    DECLARE_HYPERCALL;
+    DECLARE_HYPERCALL_BOUNCE(op, count * op_size, XC_HYPERCALL_BUFFER_BOUNCE_BOTH);
+
+    if ( xc_hypercall_bounce_pre(xch, op) )
+    {
+        PERROR("Could not bounce buffer for grant table op hypercall");
+        goto out1;
+    }
+
+    hypercall.op = __HYPERVISOR_grant_table_op;
+    hypercall.arg[0] = cmd;
+    hypercall.arg[1] = HYPERCALL_BUFFER_AS_ARG(op);
+    hypercall.arg[2] = count;
+
+    ret = do_xen_hypercall(xch, &hypercall);
+
+    xc_hypercall_bounce_post(xch, op);
+
+ out1:
+    return ret;
+}
+
+int xc_gnttab_get_version(xc_interface *xch, int domid)
+{
+    struct gnttab_get_version query;
+    int rc;
+
+    query.dom = domid;
+    rc = xc_gnttab_op(xch, GNTTABOP_get_version, &query, sizeof(query),
+                      1);
+    if ( rc < 0 )
+        return rc;
+    else
+        return query.version;
+}
+
+static void *_gnttab_map_table(xc_interface *xch, int domid, int *gnt_num)
+{
+    int rc, i;
+    struct gnttab_query_size query;
+    struct gnttab_setup_table setup;
+    DECLARE_HYPERCALL_BUFFER(unsigned long, frame_list);
+    xen_pfn_t *pfn_list = NULL;
+    grant_entry_v1_t *gnt = NULL;
+
+    if ( !gnt_num )
+        return NULL;
+
+    query.dom = domid;
+    rc = xc_gnttab_op(xch, GNTTABOP_query_size, &query, sizeof(query), 1);
+
+    if ( rc || (query.status != GNTST_okay) )
+    {
+        ERROR("Could not query dom's grant size\n", domid);
+        return NULL;
+    }
+
+    *gnt_num = query.nr_frames * (PAGE_SIZE / sizeof(grant_entry_v1_t) );
+
+    frame_list = xc_hypercall_buffer_alloc(xch, frame_list, query.nr_frames * sizeof(unsigned long));
+    if ( !frame_list )
+    {
+        ERROR("Could not allocate frame_list in xc_gnttab_map_table\n");
+        return NULL;
+    }
+
+    pfn_list = malloc(query.nr_frames * sizeof(xen_pfn_t));
+    if ( !pfn_list )
+    {
+        ERROR("Could not allocate pfn_list in xc_gnttab_map_table\n");
+        goto err;
+    }
+
+    setup.dom = domid;
+    setup.nr_frames = query.nr_frames;
+    set_xen_guest_handle(setup.frame_list, frame_list);
+
+    /* XXX Any race with other setup_table hypercall? */
+    rc = xc_gnttab_op(xch, GNTTABOP_setup_table, &setup, sizeof(setup),
+                      1);
+
+    if ( rc || (setup.status != GNTST_okay) )
+    {
+        ERROR("Could not get grant table frame list\n");
+        goto err;
+    }
+
+    for ( i = 0; i < setup.nr_frames; i++ )
+        pfn_list[i] = frame_list[i];
+
+    gnt = xc_map_foreign_pages(xch, domid, PROT_READ, pfn_list,
+                               setup.nr_frames);
+    if ( !gnt )
+    {
+        ERROR("Could not map grant table\n");
+        goto err;
+    }
+
+err:
+    if ( frame_list )
+        xc_hypercall_buffer_free(xch, frame_list);
+    if ( pfn_list )
+        free(pfn_list);
+
+    return gnt;
+}
+
+grant_entry_v1_t *xc_gnttab_map_table_v1(xc_interface *xch, int domid,
+                                         int *gnt_num)
+{
+    if (xc_gnttab_get_version(xch, domid) == 2)
+        return NULL;
+    return _gnttab_map_table(xch, domid, gnt_num);
+}
+
+grant_entry_v2_t *xc_gnttab_map_table_v2(xc_interface *xch, int domid,
+                                         int *gnt_num)
+{
+    if (xc_gnttab_get_version(xch, domid) != 2)
+        return NULL;
+    return _gnttab_map_table(xch, domid, gnt_num);
+}
+
index 5635e2b78185cec1151f2aee239553fb8b16ab12..63b89b4786c9b46e94d176f3f4ec036e1cdf6d12 100644 (file)
@@ -608,132 +608,6 @@ int xc_gnttab_set_max_grants(xc_interface *xch,
     return 0;
 }
 
-int xc_gnttab_op(xc_interface *xch, int cmd, void * op, int op_size, int count)
-{
-    int ret = 0;
-    DECLARE_HYPERCALL;
-    DECLARE_HYPERCALL_BOUNCE(op, count * op_size, XC_HYPERCALL_BUFFER_BOUNCE_BOTH);
-
-    if ( xc_hypercall_bounce_pre(xch, op) )
-    {
-        PERROR("Could not bounce buffer for grant table op hypercall");
-        goto out1;
-    }
-
-    hypercall.op = __HYPERVISOR_grant_table_op;
-    hypercall.arg[0] = cmd;
-    hypercall.arg[1] = HYPERCALL_BUFFER_AS_ARG(op);
-    hypercall.arg[2] = count;
-
-    ret = do_xen_hypercall(xch, &hypercall);
-
-    xc_hypercall_bounce_post(xch, op);
-
- out1:
-    return ret;
-}
-
-int xc_gnttab_get_version(xc_interface *xch, int domid)
-{
-    struct gnttab_get_version query;
-    int rc;
-
-    query.dom = domid;
-    rc = xc_gnttab_op(xch, GNTTABOP_get_version, &query, sizeof(query),
-                      1);
-    if ( rc < 0 )
-        return rc;
-    else
-        return query.version;
-}
-
-static void *_gnttab_map_table(xc_interface *xch, int domid, int *gnt_num)
-{
-    int rc, i;
-    struct gnttab_query_size query;
-    struct gnttab_setup_table setup;
-    DECLARE_HYPERCALL_BUFFER(unsigned long, frame_list);
-    xen_pfn_t *pfn_list = NULL;
-    grant_entry_v1_t *gnt = NULL;
-
-    if ( !gnt_num )
-        return NULL;
-
-    query.dom = domid;
-    rc = xc_gnttab_op(xch, GNTTABOP_query_size, &query, sizeof(query), 1);
-
-    if ( rc || (query.status != GNTST_okay) )
-    {
-        ERROR("Could not query dom's grant size\n", domid);
-        return NULL;
-    }
-
-    *gnt_num = query.nr_frames * (PAGE_SIZE / sizeof(grant_entry_v1_t) );
-
-    frame_list = xc_hypercall_buffer_alloc(xch, frame_list, query.nr_frames * sizeof(unsigned long));
-    if ( !frame_list )
-    {
-        ERROR("Could not allocate frame_list in xc_gnttab_map_table\n");
-        return NULL;
-    }
-
-    pfn_list = malloc(query.nr_frames * sizeof(xen_pfn_t));
-    if ( !pfn_list )
-    {
-        ERROR("Could not allocate pfn_list in xc_gnttab_map_table\n");
-        goto err;
-    }
-
-    setup.dom = domid;
-    setup.nr_frames = query.nr_frames;
-    set_xen_guest_handle(setup.frame_list, frame_list);
-
-    /* XXX Any race with other setup_table hypercall? */
-    rc = xc_gnttab_op(xch, GNTTABOP_setup_table, &setup, sizeof(setup),
-                      1);
-
-    if ( rc || (setup.status != GNTST_okay) )
-    {
-        ERROR("Could not get grant table frame list\n");
-        goto err;
-    }
-
-    for ( i = 0; i < setup.nr_frames; i++ )
-        pfn_list[i] = frame_list[i];
-
-    gnt = xc_map_foreign_pages(xch, domid, PROT_READ, pfn_list,
-                               setup.nr_frames);
-    if ( !gnt )
-    {
-        ERROR("Could not map grant table\n");
-        goto err;
-    }
-
-err:
-    if ( frame_list )
-        xc_hypercall_buffer_free(xch, frame_list);
-    if ( pfn_list )
-        free(pfn_list);
-
-    return gnt;
-}
-
-grant_entry_v1_t *xc_gnttab_map_table_v1(xc_interface *xch, int domid,
-                                         int *gnt_num)
-{
-    if (xc_gnttab_get_version(xch, domid) == 2)
-        return NULL;
-    return _gnttab_map_table(xch, domid, gnt_num);
-}
-
-grant_entry_v2_t *xc_gnttab_map_table_v2(xc_interface *xch, int domid,
-                                         int *gnt_num)
-{
-    if (xc_gnttab_get_version(xch, domid) != 2)
-        return NULL;
-    return _gnttab_map_table(xch, domid, gnt_num);
-}
-
 /*
  * Local variables:
  * mode: C
index 774e1debc61b812b51c429206163a9ab209edf67..146816b1d3943f09648d969e60bacf6833ad887f 100644 (file)
@@ -457,18 +457,6 @@ int xc_gnttab_set_max_grants(xc_interface *xch, int xcg_handle,
     return ret;
 }
 
-grant_entry_v1_t *xc_gnttab_map_table_v1(
-    xc_interface *xch, int domid, int *gnt_num)
-{
-    return NULL;
-}
-
-grant_entry_v2_t *xc_gnttab_map_table_v2(
-    xc_interface *xch, int domid, int *gnt_num)
-{
-    return NULL;
-}
-
 /*
  * Local variables:
  * mode: C
index 41cfa63e49efad71fa52473dba74fe8b4abca1be..c6bf2276842c4a578bf7c1dd7f40d5e4f816918e 100644 (file)
@@ -312,18 +312,6 @@ void discard_file_cache(xc_interface *xch, int fd, int flush)
     errno = saved_errno;
 }
 
-grant_entry_v1_t *xc_gnttab_map_table_v1(
-    xc_interface *xch, int domid, int *gnt_num)
-{
-    return NULL;
-}
-
-grant_entry_v2_t *xc_gnttab_map_table_v2(
-    xc_interface *xch, int domid, int *gnt_num)
-{
-    return NULL;
-}
-
 /*
  * Local variables:
  * mode: C
index 28b4e4395a9c366154e3cc2a9dbd23ab639430e5..b0155e1de436f7bdea8f64b76f5d22a19657452b 100644 (file)
@@ -261,15 +261,3 @@ void discard_file_cache(xc_interface *xch, int fd, int flush)
 {
     // TODO: Implement for Solaris!
 }
-
-grant_entry_v1_t *xc_gnttab_map_table_v1(
-    xc_interface *xch, int domid, int *gnt_num)
-{
-    return NULL;
-}
-
-grant_entry_v2_t *xc_gnttab_map_table_v2(
-    xc_interface *xch, int domid, int *gnt_num)
-{
-    return NULL;
-}